<template>
  <div>
    <el-row class="tac">
      <el-col :span="24">
        <el-menu
          :unique-opened="true"
          default-active="IndexShow"
          class="el-menu-vertical-demo"
          :router="true"
        >
          <template v-for="(item, index) in navTree">
            <template v-if="item.hidden == 1">
              <!-- 有二级菜单 -->
              <el-submenu
                v-if="item.children && item.children.length > 0"
                :index="item.path"
                :key="index"
              >
                <template slot="title">
                  <i :class="item.icon"></i>
                  <span> {{ item.menuName }}</span>
                </template>

                <template v-for="(itemC, indexC) in item.children">
                  <!-- 有三级菜单 -->
                  <el-submenu
                    v-if="itemC.children && itemC.children.length > 1"
                    :index="itemC.path"
                    :key="indexC"
                  >
                    <template slot="title">
                      <i :class="itemC.icon"></i>
                      <span> {{ itemC.menuName }}</span>
                    </template>
                    <template v-for="(itemD, indexD) in itemC.children">
                      <el-menu-item :index="itemD.path" :key="indexD">
                        <i :class="itemD.icon"></i>
                        <span> {{ itemD.menuName }}</span>
                      </el-menu-item>
                    </template>
                  </el-submenu>

                  <!-- 没有有三级菜单 -->
                  <el-menu-item v-else :index="itemC.path" :key="indexC">
                    <i :class="itemC.icon"></i>
                    <span> {{ itemC.menuName }}</span>
                  </el-menu-item>
                </template>
              </el-submenu>
              <!-- 只有一级菜单 -->
              <el-menu-item v-else :index="item.path" :key="index">
                <i :class="item.icon"></i>
                <span> {{ item.menuName }}</span>
              </el-menu-item>
            </template>
          </template>
        </el-menu>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "SideBar",
  data() {
    return {
      navTree: "",
      asideHeight: 300,
    };
  },
  created() {
    const h = window.innerHeight;
    this.asideHeight = h - 121;
    let navTree = JSON.parse(localStorage.getItem("navTree"));
    console.log(navTree);
    //图标
    let icon = {
      IndexShow: "el-icon-s-home",
      BannerView: "el-icon-postcard",
      OrderView: "el-icon-s-order",
      CustomView: "el-icon-user-solid",
      CpscoreView: "el-icon-s-ticket",
      ContentView: "el-icon-document-copy",
      InsurancemgrView: "el-icon-tickets",
      CommentView: "el-icon-postcard",
      RefundmentView: "el-icon-money",
      ThirdmgrView: "el-icon-office-building",
      SettingView: "el-icon-setting",
    };
    for (let i = 0; i < navTree.length; i++) {
      // console.log(navTree[i]);
      if (
        navTree[i].menuID == 3 ||
        navTree[i].menuID == 6 ||
        navTree[i].menuID == 35 
        
      ) {
        navTree[i].children = [];
      }
      if (icon[navTree[i].icon]) {
        navTree[i].icon = icon[navTree[i].icon];
      }
      for (let j = 0; j < navTree[i].children.length; j++) {
        if (
          navTree[i].children[j].menuID == "18" ||
          navTree[i].children[j].menuID == "25" ||
          navTree[i].children[j].menuID == "30" ||
          navTree[i].children[j].menuID == "50" ||
          navTree[i].children[j].menuID == "52" ||
          navTree[i].children[j].menuID == "15"||
          navTree[i].children[j].menuID == "21"
          
        ) {
          navTree[i].children[j].children = [];
        }
        if(navTree[i].children[j].menuID==63||navTree[i].children[j].menuID==64){
          // console.log(navTree[i].children[j].menuID);/
          let that=j;
          let thatI=i;
          console.log();
          console.log(that);
          setTimeout(()=>{
          console.log(navTree[thatI].children.splice(that,1));   
          console.log(navTree[thatI].children.splice(that,1) );
          },1000)
          // navTree[i].children=
        }
        if (navTree[i].children[j].menuID == "26") {
          // console.log(navTree[i].children[j].children);

          for (let k = 0; k < navTree[i].children[j].children.length; k++) {
            // console.log(navTree[i].children[j].children[k]);
            if (navTree[i].children[j].children[k].menuID == "68") {
                navTree[i].children[j].children.splice(k,1)
            }

            
          }
        }
      }
    }

    console.log(navTree);
    this.navTree = navTree;
    this.$router.push("/IndexShow");
  },
  methods: {
    
  },
};
</script>